CMAKE_MINIMUM_REQUIRED (VERSION 2.6 FATAL_ERROR)

PROJECT (pthreads-w32)

####################
# Pthreads version
####################
SET (PTHREADS_W32_VERSION_MAJOR 2)
SET (PTHREADS_W32_VERSION_MINOR 9)
SET (PTHREADS_W32_VERSION_PATCH 1)
SET (PTHREADS_W32_VERSION "${PTHREADS_W32_VERSION_MAJOR}.${PTHREADS_W32_VERSION_MINOR}")
SET (PTHREADS_W32_VERSION_FULL "${PTHREADS_W32_VERSION}.${PTHREADS_W32_VERSION_PATCH}")

##########################
# Pthreads configuration
##########################

# Standard CMake option for building libraries shared or static by default.
OPTION (BUILD_SHARED_LIBS "Build with shared libraries." OFF)

# Additional include directories
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR})

# Preprocessor definitions
ADD_DEFINITIONS (-D__PTW32_CONFIG_H)
ADD_DEFINITIONS (-D__CLEANUP_C)
IF (BUILD_SHARED_LIBS)
  ADD_DEFINITIONS (-DPTW32_BUILD)
ELSE (BUILD_SHARED_LIBS)
  ADD_DEFINITIONS (-DPTW32_STATIC_LIB)
ENDIF (BUILD_SHARED_LIBS)

SET (RESOURCE_COMPILE_DEFINITIONS "PTW32_RC_MSC")
IF (CMAKE_CL_64)
  SET (RESOURCE_COMPILE_DEFINITIONS "${RESOURCE_COMPILE_DEFINITIONS};PTW32_ARCHx64")
ELSE (CMAKE_CL_64)
  SET (RESOURCE_COMPILE_DEFINITIONS "${RESOURCE_COMPILE_DEFINITIONS};PTW32_ARCHx86")
ENDIF (CMAKE_CL_64)
SET_PROPERTY (SOURCE version.rc PROPERTY COMPILE_DEFINITIONS ${RESOURCE_COMPILE_DEFINITIONS})

SET (SOURCE_FILES
  implement.h
  pthread.c
  pthread.h
  sched.h
  semaphore.h
  #version.rc
)

ADD_LIBRARY (pthreads ${SOURCE_FILES})

# Workaround for issue 0011240: VS 2010 Win64 does not correctly set /MACHINE:x64
# in the solution project files.
IF (CMAKE_CL_64)
  SET_TARGET_PROPERTIES (pthreads PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
ENDIF (CMAKE_CL_64)

# Installation
INSTALL (TARGETS pthreads
  RUNTIME DESTINATION bin COMPONENT Runtime
  LIBRARY DESTINATION lib COMPONENT Runtime
  ARCHIVE DESTINATION lib COMPONENT Development
)